using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using QLNhaSach.BUS.DTO;

namespace QLNhaSach.DAO
{
    public class QuyDinhDAO
    {
        //Hien thi danh sach quy dinh
        public static DataTable DSQD()
        {
            string sql = "SELECT *FROM QuyDinh";
            return Config.AccessHelper.ExecuteQuery(sql);
        }

        //Tao quy dinh
        public static bool TaoQD(QuyDinhDTO qd)
        {
            try
            {
                //tao cau truy van va thuc thi cau truy van
                string sql = "INSERT INTO QuyDinh(MaQD,GiaTri,MoTa,TinhTrang) VALUES('" +
                qd.MaQD + "'," +
                qd.GiaTri + ",'" +
                qd.MoTa + "'," +
                qd.TinhTrang + ")";
                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }

        //Cap nhat quy dinh
        public static bool CapNhatQD(QuyDinhDTO qd)
        {
            try
            {
                //tao cau truy van va thuc thi cau truy van
                string sql = "UPDATE QuyDinh SET MaQD='" + qd.MaQD + "',GiaTri=" + qd.GiaTri + ",MoTa='" + qd.MoTa + "',TinhTrang=" + qd.TinhTrang + " where id=" + qd.id;
                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
